<%#
 Copyright 2013-2020 the original author or authors from the JHipster project.

 This file is part of the JHipster project, see https://www.jhipster.tech/
 for more information.

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-%>
package <%= packageName %>.service;

<%_
const instanceType = (dto === 'mapstruct') ? asDto(entityClass) : asEntity(entityClass);
const instanceName = (dto === 'mapstruct') ? asDto(entityInstance) : asEntity(entityInstance);
const optionalOrMono = (reactive === true) ? 'Mono' : 'Optional';
const listOrFlux = (reactive === true) ? 'Flux' : 'List';
const pageOrFlux = (reactive === true) ? 'Flux' : 'Page';
_%>
<%_ if (dto === 'mapstruct') { _%>
import <%= packageName %>.service.dto.<%= asDto(entityClass) %>;
<%_ } else { _%>
import <%= packageName %>.domain.<%= asEntity(entityClass) %>;
<%_ } _%>
<%_ if (pagination !== 'no' || relationshipsContainEagerLoad) { _%>

    <%_ if (!reactive) { _%>
import org.springframework.data.domain.Page;
    <%_ } _%>
import org.springframework.data.domain.Pageable;
<%_ } _%>
<%_ if (reactiveRepositories) { _%>
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
<%_ } _%>

<%_ if (pagination === 'no' || fieldsContainNoOwnerOneToOne === true) { _%>
import java.util.List;
<%_ } _%>
<%_ if (!reactive) { _%>
import java.util.Optional;
<%_ } _%>
<%_ if (databaseType === 'cassandra') { _%>
import java.util.UUID;
<%_ } _%>

/**
 * Service Interface for managing {@link <% if (dto === 'mapstruct') { %><%= packageName %>.domain.<% } %><%= asEntity(entityClass) %>}.
 */
public interface <%= entityClass %>Service {

    /**
     * Save a <%= entityInstance %>.
     *
     * @param <%= instanceName %> the entity to save.
     * @return the persisted entity.
     */
    <% if (reactive) { %>Mono<<% } %><%= instanceType %><% if (reactive) { %>><% } %> save(<%= instanceType %> <%= instanceName %>);

    /**
     * Partially updates a <%= entityInstance %>.
     *
     * @param <%= instanceName %> the entity to update partially.
     * @return the persisted entity.
     */
<% if (reactive) { %>Mono<<% } %><%= instanceType %><% if (reactive) { %>><% } %> partialUpdate(<%= instanceType %> <%= instanceName %>);

    /**
     * Get all the <%= entityInstancePlural %>.
     *<% if (pagination !== 'no') { %>
     * @param pageable the pagination information.<% } %>
     * @return the list of entities.
     */
    <% if (pagination !== 'no') { %><%= pageOrFlux %><<%= instanceType %><% } else { %><%= listOrFlux %><<%= instanceType %><% } %>> findAll(<% if (pagination !== 'no') { %>Pageable pageable<% } %>);
<% for (idx in relationships) { if (relationships[idx].relationshipType === 'one-to-one' && relationships[idx].ownerSide !== true) { -%>
    /**
     * Get all the <%= asDto(entityClass) %> where <%= relationships[idx].relationshipNameCapitalized %> is {@code null}.
     *
     * @return the {@link <%= listOrFlux %>} of entities.
     */
    <%= listOrFlux %><<%= instanceType %>> findAllWhere<%= relationships[idx].relationshipNameCapitalized %>IsNull();
<%_ } } _%>

    <%_ if (relationshipsContainEagerLoad) { _%>
    /**
     * Get all the <%= entityInstancePlural %> with eager load of many-to-many relationships.
     *
     * @param pageable the pagination information.
     * @return the list of entities.
     */
    <%= pageOrFlux %><<%= instanceType %>> findAllWithEagerRelationships(Pageable pageable);

    <%_ } _%>
<%_ if (reactive) { _%>
    /**
    * Returns the number of <%= entityInstancePlural %> available.
    * @return the number of entities in the database.
    *
    */
    Mono<Long> countAll();
    <%_ if (searchEngine === 'elasticsearch') { _%>

    /**
    * Returns the number of <%= entityInstancePlural %> available in search repository.
    *
    */
    Mono<Long> searchCount();
    <%_  } _%>

<%_  } _%>

    /**
     * Get the "id" <%= entityInstance %>.
     *
     * @param id the id of the entity.
     * @return the entity.
     */
    <%= optionalOrMono %><<%= instanceType %>> findOne(<%= primaryKeyType %> id);

    /**
     * Delete the "id" <%= entityInstance %>.
     *
     * @param id the id of the entity.
<%_ if (reactive) { _%>
     * @return a Mono to signal the deletion
<%_ } _%>
     */
    <%- reactive ? 'Mono<Void>' : 'void' %> delete(<%= primaryKeyType %> id);<% if (searchEngine !== false) { %>

    /**
     * Search for the <%= entityInstance %> corresponding to the query.
     *
     * @param query the query of the search.
     * <% if (pagination !== 'no') { %>
     * @param pageable the pagination information.<% } %>
     * @return the list of entities.
     */
    <% if (pagination !== 'no') { %><%= pageOrFlux %><<%= instanceType %><% } else { %><%= listOrFlux %><<%= instanceType %><% } %>> search(String query<% if (pagination !== 'no') { %>, Pageable pageable<% } %>);<% } %>
}
